#include "luarun.h"

static int pin_write(lua_State *L)
{
	int iPin = lua_tonumber(L,1);	
    int iState = lua_tonumber(L,2);
    os_pin_write((os_base_t)iPin, (os_base_t)iState);
	return 0;
}

static int pin_mode(lua_State *L)
{
	int iPin = lua_tonumber(L,1);	
    int iMode = lua_tonumber(L,2);
    os_pin_mode((os_base_t)iPin, (os_base_t)iMode);
	return 0;
}

static int tim_sleep(lua_State *L)
{
		int iNum = lua_tonumber(L,1);	
    os_task_msleep((os_base_t)iNum);
		return 0;
}

static int Pin_init(void)
{
		int iRet = LUA_OK;
    lua_rd_t iPin, iTim;
    iPin = LUA_REG("Pin");
    LUA_FUN(iPin, "write", pin_write);
    LUA_FUN(iPin, "mode", pin_mode);
		iTim = LUA_REG("Tim");
		LUA_FUN(iTim, "sleep", tim_sleep);
    return iRet;
} 
OS_ENV_INIT(Pin_init, OS_INIT_SUBLEVEL_LOW);
